package cn.ynrcb.personnelfile.sysadmin.controller;


import cn.ynrcb.personnelfile.sysadmin.entity.SysUserEntity;
import cn.ynrcb.personnelfile.sysadmin.service.SysUserRoleService;
import org.apache.shiro.SecurityUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;


/**
 * Controller公共组件
 */
public abstract class AbstractController {
	protected Logger logger = LoggerFactory.getLogger(getClass());

	@Autowired
	private SysUserRoleService sysUserRoleService;

	protected SysUserEntity getUser() {
		return (SysUserEntity) SecurityUtils.getSubject().getPrincipal();
	}

	protected Long getUserId() {
		return getUser().getUserId();
	}

	protected Integer getUserRoleId() {
		List<Integer> roles = sysUserRoleService.queryRoleIdList(getUser().getUserId());
		return Integer.parseInt(roles.get(0).toString());
	}

//	protected String getInnerCode() {
//		SysOrgEntity org = sysOrgService.getById(getUser().getOrgId());
//		return org.getInnerCode();
//	}

	protected Long getCurrentUserId() {
		return getUser().getUserId();
	}
}
